/**
 * Copyright (C) 2011 Taobao Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.taobao.jaket.builder;

import java.util.List;

import junit.framework.Assert;

import org.junit.Test;

import com.taobao.jaket.Builder;
import com.taobao.jaket.model.MethodDefinition;
import com.taobao.jaket.model.ServiceDefinition;
import com.taobao.jaket.model.SignatureDefinition;
import com.taobao.jaket.model.TypeDefinition;
import com.taobao.jaket.test.service.ServiceWithGenericTypeSet;
import com.taobao.jaket.type.TypeTestSupport;

/**
 * builder test: for service extends support
 * 
 * @author Xueqiang Mi
 */
public class BuilderTest_ServiceWithGenericTypeSet extends TypeTestSupport {

    @Test
    public void testServiceWithGenericType1() {
        ServiceDefinition sd = Builder.buildJsonSchema(ServiceWithGenericTypeSet.class);
        Assert.assertNotNull(sd);
        Assert.assertEquals(1, sd.getMethods().size());

        // validate service metadata details
        // System.out.println(new Gson().toJson(sd));
        Assert.assertNotNull(sd);
        Assert.assertNotNull(sd.getSignature());
        Assert.assertNotNull(sd.getMethods());

        SignatureDefinition sig = sd.getSignature();
        Assert.assertEquals(ServiceWithGenericTypeSet.class.getCanonicalName(), sig.getCanonicalName());
        Assert.assertEquals("1.0.0", sig.getVersion());

        List<MethodDefinition> methods = sd.getMethods();
        Assert.assertEquals(1, methods.size());
        MethodDefinition md = methods.get(0);

        // method name
        Assert.assertEquals("sayHello", md.getName());
        // return type
        assertType("string", md.getReturnType());
        // parameter type
        List<TypeDefinition> paramTypes = md.getParameters();
        Assert.assertEquals(1, paramTypes.size());
        TypeDefinition paramType = paramTypes.get(0);
        assertType("array", paramType);
        // parameter generic type
        Assert.assertNotNull(paramType.getItems());
        Assert.assertEquals(1, paramType.getItems().size());
        TypeDefinition genericType = paramType.getItems().get(0);
        assertType("number", genericType, "id");
        assertType("string", genericType, "name");
        assertType("number", genericType, "age");
    }

    @Test
    public void testServiceWithGenericType2() {

    }
}
